using  GoodDotNet.Core.Entity;
using  GoodDotNet.Core.IRepository;
using GoodDotNet.Core.Repository.BASE;
using GoodDotNet.Core.Data;
using Microsoft.EntityFrameworkCore;
using GoodDotNet.Core.Model;

namespace GoodDotNet.Core.Repository
{
  
  /**
   *
   * @author 大钊
   * @since 2023/9/6 12:01:17
   */
   public class  TestRepository : BaseRepository< Test>, TestIRepository
    {
        public  TestRepository(MyDbContext context) : base(context)
        {
        }
       


		
		
		 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// @author 大钊
		/// @since 2023/9/7 14:53:09
		public List<TestGetPageTestDataModel> GetPageTest( TestGetPageTestParModel pars ){
		   var query = from test in this.context.Test
		    join user in this.context.User on test.UserId equals user.Id into TestUser from user in TestUser .DefaultIfEmpty()
		    where test.Id==pars.Id
			orderby test.InsertTime,user.Birthday    descending
		    select new TestGetPageTestDataModel
		   	{
		   		
				Id=test.Id,
				Name=test.Name,
				Age=test.Age,
				UserCard=user.Card,
				UserNickName=user.NickName
		   	};
		    return query.Skip((pars.PageIndex - 1) * pars.PageSize)
		    .Take(pars.PageSize)
		    .ToList();
		}
		
		


		
		
		 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// @author 大钊
		/// @since 2023/9/7 15:00:24
		public int CountTest( TestCountTestParModel pars ){
			var query = from test in this.context.Test
						join user in this.context.User on test.UserId equals user.Id into TestUser from user in TestUser.DefaultIfEmpty()
						where user.Id == pars.UserId select test;
		  return query.Count();
		}
		
		

}
 }
